//------------------------------------------------------------
//  Filename: co_processor_wrapper.v
//   
//  Author  : wlduan@gmail.com
//  Revise  : 2016-10-19 13:08
//  Description: 
//   
//  Copyright (C) 2014, YRBD, Inc. 					      
//  All Rights Reserved.                                       
//-------------------------------------------------------------
//
`timescale 1ns/1ps
 
module CO_PROCESSOR_WRAPPER ( 
    input  wire        clk_100mhz,
    input  wire        resetn,

    input  wire [15:0] camera0_x_org_cnt,
    input  wire [15:0] camera0_y_org_cnt,
    input  wire [15:0] camera1_x_org_cnt,
    input  wire [15:0] camera1_y_org_cnt,
    //-------------------------------
    input  wire [31:0] fusion_base_x,
    input  wire [7:0]  fusion_pix_black, 
    input  wire [11:0] fusion_fast_l_x,
    input  wire [11:0] fusion_slow_l_x,
    input  wire [11:0] fusion_fast_r_x,
    input  wire [11:0] fusion_slow_r_x,
    input  wire [7:0]  fusion_face_sens,
    input  wire [7:0]  fusion_edge_sens,
    input  wire [31:0] fusion_push_ctrl,
    output wire [31:0] fusion_push_state,
    output wire [31:0] fusion_proc_state,
    input  wire [31:0] fusion_force_cfg,
    input  wire [31:0] fusion_time_cfg,
    output wire        fusion_proc_intr,

    input  wire [7:0]  touch_status,
    output wire [31:0] fiber_push_status,
    input  wire [31:0] fiber_aux_ctrl,
    //-------------------------------
    input  wire        force_pause_l,
    input  wire        force_pause_r,

    output wire [31:0] gaoya_ctrl_time,
    output wire [7:0]  gaoya_ctrl_force,    

    output wire [31:0] motor_move_l,
    output wire [31:0] motor_move_r,
    
    output wire [31:0] calibera_edge_x,
    output wire [31:0] calibera_edge_y,
    output wire [31:0] engineer_edge_x,
    output wire [31:0] engineer_edge_y,  

    input  wire        coproc0_wr_en,
    input  wire [32:0] coproc0_din  ,

    input  wire        coproc1_wr_en,
    input  wire [32:0] coproc1_din  ,

    input  wire [11:0] cpu_mem_addrb,
    output reg  [31:0] cpu_mem_doutb,
       
    output wire        cpu_mem_ready0,
    output wire        cpu_mem_ready1
);  
//-------------------------------
wire [31:0]     p0_move_porc_data;
wire            p0_move_porc_last;
wire            p0_move_porc_v   ;

wire [31:0]     p1_move_porc_data;
wire            p1_move_porc_last;
wire            p1_move_porc_v   ;

wire [11:0]     cpu_mem_addrb0   ;
wire [31:0]     cpu_mem_doutb0   ;

wire [11:0]     cpu_mem_addrb1   ;
wire [31:0]     cpu_mem_doutb1   ;

wire            sensor0_wr_en  = coproc0_wr_en;
wire [32:0]     sensor0_din    = coproc0_din  ;

wire            sensor1_wr_en  = coproc1_wr_en;
wire [32:0]     sensor1_din    = coproc1_din  ;
//-------------------------------
assign cpu_mem_addrb0 = cpu_mem_addrb;
assign cpu_mem_addrb1 = cpu_mem_addrb;
//-------------------------------
always @(*) begin
    if (cpu_mem_addrb[11:10] == 2'h1) begin
        cpu_mem_doutb = cpu_mem_doutb0;
    end
    else if (cpu_mem_addrb[11:10] == 2'h2) begin
        cpu_mem_doutb = cpu_mem_doutb1;
    end
    else begin
        cpu_mem_doutb = 32'b0;
    end
end
//-------------------------------
CAMERA_FIBER_INFO CAMERA_FIBER_INFO_inst0( 
    .clk_100mhz           ( clk_100mhz            ) ,
    .resetn               ( resetn                ) ,
    
    .camera_x_org_cnt     ( camera0_x_org_cnt     ) ,
    .camera_y_org_cnt     ( camera0_y_org_cnt     ) ,
    
    .fusion_base_x        ( fusion_base_x[11:0]   ) ,
    .fusion_pix_black     ( fusion_pix_black      ) ,
    .fusion_face_sens     ( fusion_face_sens      ) ,
    .fusion_edge_sens     ( fusion_edge_sens      ) ,
    
    .sensor_base          ( 2'h1                  ) ,
    .sensor_wr_en         ( sensor0_wr_en         ) ,
    .sensor_din           ( sensor0_din           ) ,

    .cpu_mem_addrb        ( cpu_mem_addrb0        ) ,
    .cpu_mem_doutb        ( cpu_mem_doutb0        ) ,
    .cpu_mem_ready        ( cpu_mem_ready0        ) ,

    .calibera_edge        ( calibera_edge_x       ) ,
    .engineer_edge        ( engineer_edge_x       ) ,
    .move_porc_data       ( p0_move_porc_data     ) ,
    .move_porc_last       ( p0_move_porc_last     ) ,
    .move_porc_v          ( p0_move_porc_v        ) 
);  

CAMERA_FIBER_INFO CAMERA_FIBER_INFO_inst1( 
    .clk_100mhz           ( clk_100mhz            ) ,
    .resetn               ( resetn                ) ,

    .camera_x_org_cnt     ( camera1_x_org_cnt     ) ,
    .camera_y_org_cnt     ( camera1_y_org_cnt     ) ,

    .fusion_base_x        ( fusion_base_x[27:16]  ) ,
    .fusion_pix_black     ( fusion_pix_black      ) ,
    .fusion_face_sens     ( fusion_face_sens      ) ,
    .fusion_edge_sens     ( fusion_edge_sens      ) ,

    .sensor_base          ( 2'h2                  ) ,
    .sensor_wr_en         ( sensor1_wr_en         ) ,
    .sensor_din           ( sensor1_din           ) ,

    .cpu_mem_addrb        ( cpu_mem_addrb1        ) ,
    .cpu_mem_doutb        ( cpu_mem_doutb1        ) ,
    .cpu_mem_ready        ( cpu_mem_ready1        ) ,
    
    .calibera_edge        ( calibera_edge_y       ) ,
    .engineer_edge        ( engineer_edge_y       ) ,
    .move_porc_data       ( p1_move_porc_data     ) ,
    .move_porc_last       ( p1_move_porc_last     ) ,
    .move_porc_v          ( p1_move_porc_v        ) 
  
); 

FIBER_MOVE_PROC FIBER_MOVE_PROC_inst0( 
    .clk_100mhz           ( clk_100mhz          ) ,
    .resetn               ( resetn              ) ,

    .touch_status         ( touch_status        ) ,
    .fusion_push_ctrl     ( fusion_push_ctrl    ) ,
    .fusion_push_state    ( fusion_push_state   ) ,
    .fusion_proc_state    ( fusion_proc_state   ) ,
    .fusion_fast_l_x      ( fusion_fast_l_x     ) ,
    .fusion_slow_l_x      ( fusion_slow_l_x     ) ,
    .fusion_fast_r_x      ( fusion_fast_r_x     ) ,
    .fusion_slow_r_x      ( fusion_slow_r_x     ) ,
    .fusion_force_cfg     ( fusion_force_cfg    ) , 
    .fusion_time_cfg      ( fusion_time_cfg     ) ,
    .fusion_proc_intr     ( fusion_proc_intr    ) ,
    
    .fiber_push_status    ( fiber_push_status   ) ,
    .fiber_aux_ctrl       ( fiber_aux_ctrl      ) ,

    .p0_move_porc_data    ( p0_move_porc_data   ) ,
    .p0_move_porc_last    ( p0_move_porc_last   ) ,
    .p0_move_porc_v       ( p0_move_porc_v      ) ,
        
    .p1_move_porc_data    ( p1_move_porc_data   ) ,
    .p1_move_porc_last    ( p1_move_porc_last   ) ,
    .p1_move_porc_v       ( p1_move_porc_v      ) ,    

    .gaoya_ctrl_time      ( gaoya_ctrl_time     ) ,
    .gaoya_ctrl_force     ( gaoya_ctrl_force    ) ,

    .force_pause_l        ( force_pause_l       ) ,
    .force_pause_r        ( force_pause_r       ) ,

    .motor_move_l         ( motor_move_l        ) ,
    .motor_move_r         ( motor_move_r        ) 
); 

endmodule
